package com.situ.mall.controller;

import com.situ.imall.util.JSONResult;
import com.situ.imall.util.LayUiTableDataUtil;
import com.situ.imall.util.RedisConstant;
import com.situ.mall.pojo.Product;
import com.situ.mall.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @ClassName ProductController
 * @Description TODO
 * @Author 周轩霆
 * @Date 2022/8/22 10:48
 **/
@Controller
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private IProductService productService;

    @Autowired
    private RedisTemplate redisTemplate;

    @RequestMapping("/selectById")
    @ResponseBody
    public Product selectById(Integer id) {
        return productService.selectById(id);
    }

    @RequestMapping("/selectByPage")
    @ResponseBody
    public LayUiTableDataUtil selectByPage(@RequestParam Map params) {
        //获取前台分页数据
        String page = (String) params.get("page");
        String limit = (String) params.get("limit");
        LayUiTableDataUtil dataResult = productService.selectByPage(Integer.parseInt(page), Integer.parseInt(limit));
        return dataResult;
    }

    @RequestMapping("/add")
    @ResponseBody
    public LayUiTableDataUtil addProduct(Product product) {
        return productService.addProduct(product);
    }

    @RequestMapping("/deleteById")
    @ResponseBody
    public LayUiTableDataUtil deleteProductById(Integer id) {
        //根据id删除
        return productService.deleteProductById(id);
    }
    @RequestMapping("/deleteAll")
    @ResponseBody
    public JSONResult deleteAll(@RequestParam("ids[]") String[] idArray) {
         //批量删除
        return productService.deleteAll(idArray);

    }

}